package websocket;

import org.json.JSONException;
import org.json.JSONObject;

public class ws_ans 
{
	public class action
	{
		public action(JSONObject action)
		{
			if(null == action)
			{
				return;
			}
			type = action.optString("type");
			code = action.optString("code");
			id = action.optString("id");
		}
		public String type = null;
		public String code = null;
		public String id = null;
	}
	public class data
	{
		public data(JSONObject data)
		{
			if(null == data)
			{
				return;
			}
			try 
			{
				sheetId = data.getString("sheetId");
			} catch (JSONException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		public String sheetId = null;
	}
	public class result
	{
		public result(JSONObject result)
		{
			if(null == result)
			{
				return;
			}
			message = result.optString("message");
			statusCode = result.optString("statusCode");
		}
		public String message = null;
		public String statusCode = null;
	}
	public action m_action = null;
	public data m_data = null;
	public result m_result = null;
	public String m_name = null;
	public String m_pass = null;
	private void init(JSONObject obj,String name,String pass)
	{
		if(obj == null)
		{
			return;
		}
		JSONObject obj_tmp = obj.optJSONObject("action");
		if(null != obj_tmp)
		{
			m_action = new action(obj_tmp);
		}
		
		obj_tmp = obj.optJSONObject("data");
		if(null != obj_tmp)
		{
			m_data = new data(obj_tmp);
		}
		
		obj_tmp = obj.optJSONObject("result");
		if(null != obj_tmp)
		{
			m_result = new result(obj_tmp);
		}
		
		m_name = name;
		m_pass = pass;
	}
	public ws_ans(String jsonstr,String name,String pass)
	{
		JSONObject obj = null;
		try 
		{
			obj = new JSONObject(jsonstr);
		} catch (JSONException e) 
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		init(obj,name,pass);
	}
	public ws_ans(JSONObject obj,String name,String pass)
	{
		init(obj,name,pass);
	}
}
